//
//  KVNHotHouseSummaryTableViewCell.m
//  Test1
//
//  Created by KelvinYeung on 15/7/19.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "KVNHotHouseSummaryTableViewCell.h"

@interface KVNHotHouseSummaryTableViewCell()

@property UIImageView* houseImageView;//房子图片
@property UILabel * addressLabel;
@property UILabel * detailsLabel;
@property UILabel * titleLabel;
@property UILabel * daysLabel;
@property UILabel * preferentialLabel;
@property UILabel * priceLabel;

@end

@implementation KVNHotHouseSummaryTableViewCell
@synthesize houseImageView;
@synthesize addressLabel;
@synthesize detailsLabel;
@synthesize titleLabel;
@synthesize daysLabel;
@synthesize preferentialLabel;
@synthesize priceLabel;


- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self setAccessoryType:UITableViewCellAccessoryNone];
    if(self){
        [self initSubView];
    }
    return self;
}


#pragma mark 初始化视图
- (void) initSubView {
    //图片控件
    houseImageView = [[UIImageView alloc] init];
    houseImageView.frame = CGRectMake(10, 10, 100, 80);
    houseImageView.backgroundColor = [UIColor greenColor];
    [self addSubview:houseImageView];
    
    //标题
    titleLabel = [[UILabel alloc] init];
    [titleLabel setFrame:CGRectMake(120, 10, 150, 20)];
    titleLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:titleLabel];
    
    //详情
    detailsLabel = [[UILabel alloc] init];
    [self addSubview:detailsLabel];
    
    //地址
    addressLabel = [[UILabel alloc] init];
    [addressLabel setFrame:CGRectMake(120, 30, 150, 20)];
    addressLabel.font = [UIFont systemFontOfSize:12];
    addressLabel.textColor = [UIColor grayColor];

    [self addSubview:addressLabel];
    
    //优惠
    preferentialLabel = [[UILabel alloc] init];
    [preferentialLabel setFrame:CGRectMake(120, 50, 100, 20)];
    preferentialLabel.font = [UIFont systemFontOfSize:12];
    preferentialLabel.textColor = [UIColor grayColor];
    [self addSubview:preferentialLabel];
    
    //价格
    priceLabel = [[UILabel alloc] init];
    [priceLabel setFrame:CGRectMake(120, 70, 90, 20)];
    priceLabel.font = [UIFont systemFontOfSize:16];
    priceLabel.textColor = [UIColor redColor];
    [self addSubview:priceLabel];
    
    //剩余天数
    daysLabel = [[UILabel alloc] init];
    [daysLabel setFrame:CGRectMake(270, 10, 70, 20)];
    daysLabel.font = [UIFont systemFontOfSize:12];
    daysLabel.textColor = [UIColor redColor];
    [self addSubview:daysLabel];
    
}

- (void) setHouseSummary:(NSDictionary *)houseSummary{

    //设置图片大小和位置
    UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[houseSummary objectForKey:@"defaultImage"]]]];
    [houseImageView setImage:image];

    
    //设置标题大小和位置
    [titleLabel setText:[houseSummary objectForKey:@"houseName"]];
    //设置地址
    [addressLabel setText:[houseSummary objectForKey:@"address"]];

    //设置优惠
    [preferentialLabel setText:[houseSummary objectForKey:@"perferentialContent"]];

    //设置价格
    NSString *priceString = [NSString stringWithFormat:@"%@元/m2",[houseSummary objectForKey:@"price"]];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:priceString];

    [attrString addAttribute:(id)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(priceString.length - 1, 1)];
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(priceString.length - 1, 1)];
    [priceLabel setAttributedText:attrString];

    
    
    //设置剩余天数
    [daysLabel setText:[NSString stringWithFormat:@"%@",[houseSummary objectForKey:@"preferentialEndtime"]]];
    

}




//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//
//    // Configure the view for the selected state
//}

@end
